import { ElLoading } from 'element-plus'

let loadingInstance: any = null
export const useGlobalLoading = () => {
  const showLoading = (showText = '') => {
    loadingInstance = ElLoading.service({
      lock: true,
      text: showText,
      background: 'rgba(0, 0, 0, 0.7)',
      customClass: 'scan-tips'
    })
  }
  const hideLoading = () => {
    if (loadingInstance) {
      loadingInstance.close()
      loadingInstance = null
    }
  }

  return {
    showLoading,
    hideLoading,
  }
}
